import xml.dom.minidom
from xml.dom.minidom import parse
import cv2
import matplotlib.pyplot as plt

DOMTree = parse('data/Low-Annotations/1043-n000001-Shiba_Dog/n100001.jpeg.xml')
collection = DOMTree.documentElement
img = cv2.imread('data/low-resolution/1043-n000001-Shiba_Dog/n100001.jpeg')
headbndbox = collection.getElementsByTagName("headbndbox")[0]
xmin = int(headbndbox.getElementsByTagName("xmin")[0].childNodes[0].data)
ymin = int(headbndbox.getElementsByTagName("ymin")[0].childNodes[0].data)
xmax = int(headbndbox.getElementsByTagName("xmax")[0].childNodes[0].data)
ymax = int(headbndbox.getElementsByTagName("ymax")[0].childNodes[0].data)
cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0,255,0), 2)
bodybndbox = collection.getElementsByTagName("bodybndbox")[0]
xmin = int(bodybndbox.getElementsByTagName("xmin")[0].childNodes[0].data)
ymin = int(bodybndbox.getElementsByTagName("ymin")[0].childNodes[0].data)
xmax = int(bodybndbox.getElementsByTagName("xmax")[0].childNodes[0].data)
ymax = int(bodybndbox.getElementsByTagName("ymax")[0].childNodes[0].data)
cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0,255,255), 2)

cv2.imwrite('t.jpg',img)

# import pylab as pl
# pl.figure(figsize=(20,20))
# pl.imshow(img[:,:,::-1])
# pl.savefig()
